*******************************************************************************
* Replication file for "Doing things right versus doing the right things?"

* Contact: bernhard.reinsberg@glasgow.ac.uk
* Date: 31 May 2025
*******************************************************************************
  
  use "GPEDC_PDMS_replication", clear 
  
  
* Factor analysis
*******************************************************************************

* All variables 

  ** Table 1 
  factor dr_align_* dr_pred3y dr_csys1-dr_csys4 dr_budcov* dr_untied, fa(2)
  
  ** Table 2
  predict OwnTec OwnPol
  
  ** Figure 1 
  graph bar OwnPol OwnTec if OwnPol!=. & OwnTec!=., over(diso, label(angle(90))) scheme(s1mono) ytitle(Ownership performance) legend(lab(1 "Ownership over policy goals") lab(2 "Ownership over implementation"))
  
  ** Table A2 
  factor dr_align_*, fa(1)
  factor dr_csys1-dr_csys4 dr_pred3y dr_budcov* dr_untied, fa(1)
  
   
* Longest possible dataset of procedural-technical aid effectiveness

  ** 2005-2017
  factor dr_csys1-dr_csys4 dr_untied, fa(1)
  predict f2long

  factor dr_csys1-dr_csys4 dr_untied dr_budcov*, fa(1)
  predict f2short
  
  factor dr_align_*, fa(1)
  predict f1align
  
  ** Figure 2
  graph bar f2long f1, over(year) scheme(s1mono) ytitle(Alignment index) legend(lab(1 "Technical alignment") lab(2 "Goal alignment"))

  
  ** Figure A1 
  graph bar f2long f1, over(year) over(bi, relabel(1 "Multilateral donors" 2 "Bilateral donors")) scheme(s1mono) ytitle(Alignment index) legend(lab(1 "Technical alignment") lab(2 "Goal alignment"))

  ** Figure A2
  graph bar f2long f1 if bi==1, over(year) over(dac, relabel(1 "Non-DAC donors" 2 "DAC donors")) scheme(s1mono) ytitle(Alignment index) legend(lab(1 "Technical alignment") lab(2 "Goal alignment"))
  
  

* Adding outcome data
*******************************************************************************

  g iso3=riso
  sort iso3 year 
  merge iso3 year using "SDG_index_change"
  tab _m
  drop if _m==2
  drop iso3 _m
  
  sort id time
  g st_d_f1=d.f1
  g st_d_f2=d.f2long
  g lt_d_f2=f2long-l5.f2long
  
  g st_d_f2s=d.f2short
  g lt_d_f2s=f2short-l5.f2short 
    
  keep if year==2017

  
* OLS regression

  eststo b11: qui reg st_d_sdg st_d_f2s, cl(rcode)
  eststo b12: qui reg st_d_sdg st_d_f1, cl(rcode)
  eststo b13: reg st_d_sdg st_d_f2s st_d_f1, cl(rcode)
  eststo b14: qui reghdfe st_d_sdg st_d_f2s, a(diso) cl(rcode)
  eststo b15: qui reghdfe st_d_sdg st_d_f1, a(diso) cl(rcode)
  eststo b16: qui reghdfe st_d_sdg st_d_f2s st_d_f1, a(diso) cl(rcode)
  
  ** Table 3
  estout b1*, drop(_cons) note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(N r2, fmt(0 3))
 
 
* IV/2SLS 
 
  egen iv_d_f1=mean(st_d_f1), by(diso)
  egen iv_d_f2s=mean(st_d_f2s), by(diso)
  
  egen r_f1=mean(f1align), by(rcode)
  egen r_f2s=mean(f2short), by(rcode) 
  
  g iv1=iv_d_f1*r_f1
  g iv2s=iv_d_f2*r_f2s
 
  cmp setup
  set matsize 800
  qui xi:reg year i.dcode

  eststo b21: qui ivreg2 st_d_sdg (st_d_f2s=iv2s) i.dcode, cl(rcode)
  eststo b22: qui ivreg2 st_d_sdg (st_d_f1=iv1) i.dcode, cl(rcode)
  eststo b23: qui cmp (st_d_sdg=st_d_f1 st_d_f2s _Idc*) (st_d_f1=iv1 _Idc*) (st_d_f2s=iv2s _Idc*), indicators(1 1 1) cl(rcode)
 
  ** Table A5 
  estout b2*, drop(_cons *dcode*) note("p-values: * 10%  ** 5%  *** 1%") starlevels(* .1 ** .05 *** .01) cells(b(star fmt(3)) se(par fmt(3))) stats(N r2u idstat, fmt(0 3 3))
 
 
** Results for other appendices available upon request **


  